/******************************************************************************
 * * mmi_modem_adaptor_ps.c - implementation of mmi-modem adaptor, packet domain sub-module
 *
 * *(C) Copyright 2019 Asr International Ltd.
 * * All Rights Reserved
 * ******************************************************************************/
#include "lv_conf.h"
#if USE_LV_WATCH_MODEM_ADAPTOR != 0
#include "mmi_modem_adaptor_ps.h"

/******************************************************************************
 *
 *         Functions
 *
 *******************************************************************************/
/**
 * initiate mmi-modem adaptor PS module
 * param (in) void
 * return  void
 */
void MMI_ModemAdp_PS_Init_Req(void)
{
}

/**
 * Setup PS data call
 * param (in) SimId:  MMI_MODEM_SIM_ID
 * return  void
 */
void MMI_Modem_PS_Setup_Data_Call(MMI_MODEM_SIM_ID SimId)
{
    printf("##interface## %s\n", __FUNCTION__);

    //set master sim id
    CMSimID cm_sim_id = (MMI_MODEM_SIM_1 == SimId) ? CM_SIM_0 : CM_SIM_1;
    CM_SetMasterSimID(cm_sim_id, NULL);

    //set connection switch
    CM_SetConnectionSwitch(1);
}

/**
 * Deactivate PS data call
 * param (in) SimId:  MMI_MODEM_SIM_ID
 * return  void
 */
void MMI_Modem_PS_Deactivate_Data_Call(MMI_MODEM_SIM_ID SimId)
{
    printf("##interface## %s\n", __FUNCTION__);
    CM_SetConnectionSwitch(0);
}

/**
 * This is used to reset apn to default
 * param (in) SimId:  MMI_MODEM_SIM_ID
 * return void
 */
void MMI_Modem_PS_Reset_Apn(MMI_MODEM_SIM_ID SimId)
{
    printf("##interface## %s\n", __FUNCTION__);

    //set auto apn mode
    setAutoApn(APN_MODE_AUTO, FALSE);

    //deactive data all
    CM_DeactiveDataCallAll();

    //setup default connection
    CM_SetupDefaultConnection();
}

#ifndef USE_LV_INTERPHONE_DEMO
/**
 * This is used to config apn
 * param (in) SimId:  MMI_MODEM_SIM_ID
 * param (in) Apn: char *
 * param (in) IpType: 0: IPV4V6;  1: IPV4;  2: IPV6
 * return void
 */
void MMI_Modem_PS_Config_Apn(MMI_MODEM_SIM_ID SimId, char *Apn, UINT8 IpType)
{
    printf("##interface## %s: %s, %d\n", __FUNCTION__, Apn, IpType);

    //set auto apn mode
    setAutoApn(APN_MODE_MANUAL, FALSE);

    //deactive data all
    CM_DeactiveDataCallAll();

    //config apn info
    //isDefault: 1: will modify LTE attach APN when call CM_SetupDataCall to active the PDP context,
    //the cid value should only set to 1, specify other value will return error
    UINT8 cid = 1;
    ApnInfo_s info;
    memset(&info, 0, sizeof(ApnInfo_s));
    strncpy(info.apn, Apn, MAX_APN_INFO_LEN);
    info.cid = cid;
    info.ipType = IpType;
    info.isDefault = 1;
    CM_ConfigApnInfo(&info);

    //setup data call
    CM_SetupDataCall(cid);
}
#endif

#endif // USE_LV_WATCH_MODEM_ADAPTOR
